<?php

use yii\helpers\Url;

$this->context->layout = false;
?>
<?php
//使用率
echo $this->render("@app/views/public/useRate.php")
?>
<head>
    <link rel="stylesheet" href="/web/css/kendo/kendo.mobile.all.min.css" type="text/css"/>
    <link rel="stylesheet" href="/web/css/kendo/kendo.blueopal.mobile.min.css" type="text/css"/>
    <style>
        .km-switch-on, .km-switch-off {
            border-radius: 5px;
        }
    </style>
</head>
<div id="Rating-Settings-List"></div>
<script type="text/x-kendo-template" id="RatingSettingsTemplate">
    <button type="button" class="k-button k-button-icontext "><span
                class="k-icon k-add"></span>新增
    </button>
    <a class="k-button k-button-icontext" onclick="onButtonAuth()"><span class="glyphicon glyphicon-cog"></span>部门类别</a>
    <a class="k-button k-button-icontext" onclick="onLeaderAuth()"><span class="glyphicon glyphicon-cog"></span>代理组长</a>
    <a class="k-button k-button-icontext" onclick="onNotCommented()"><span class="glyphicon glyphicon-cog"></span>未评五大类</a>
    <a class="k-button k-button-icontext" onclick="onHistoryRecord()"><span class="glyphicon glyphicon-cog"></span>查看历史</a>
    <a class="k-button k-button-icontext" onclick="onSummaryMaintain()"><span class="glyphicon glyphicon-cog"></span>查看总汇</a>
    <a class="k-button k-button-icontext" onclick="onSummaryManagement()"><span class="glyphicon glyphicon-cog"></span>总汇管理层</a>
    <a class="k-button k-button-icontext btn btn-info btn-lg active"><span class="glyphicon glyphicon-cog"></span>评级设置</a>
    <a class="k-button k-button-icontext" onclick="onAuthManagement()"><span class="glyphicon glyphicon-cog"></span>权限管理</a>
    <a class="k-button k-button-icontext" onclick="onAffectPrincipal()"><span class="glyphicon glyphicon-cog"></span>被影響人負責人</a>
</script>
<script>
    $("#Rating-Settings-List").kendoGrid({
        dataSource: {
            transport: {
                read: function (e) {
                    $.ajax({
                        url: "<?=Url::to(['ratingsettingslist']); ?>",
                        dataType: "json",
                        success: function (redata) {
                            e.success(redata);
                        }
                    })
                },
                update: function (e) {
                    $.ajax({
                        cache: false,
                        type: "POST",
                        dataType: "json",
                        url: "<?=Url::to(['updateratingsettings']); ?>",
                        data: e.data,
                        success: function (result) {
                            if (result.status == 1) {
                                e.success(e.data)
                            } else {
                                layer.msg(result.msg, {icon: 5});
                            }
                        }
                    });
                }
            },
            schema: {
                model: {
                    id:"departmentId",
                    fields: {
                        departmentId: { field: "departmentId", nullable: false},
                        departmentName:{ field: "departmentName", editable: false},
                        departmentStatus:{ field: "departmentStatus",type:"boolean"}
                    }
                }
            },
            pageSize: 15
        },
        editable:"inline",
        sortable: true,
        filterable: {
            extra: false,
            messages: {
                isFalse:"停用",
                isTrue:"启用"
            },
            operators: {
                string: {
                    contains: "包含",
                    doesnotcontain: "不包含",
                    eq: "等于",
                    neq: "不等于"
                }
            }
        },
        toolbar: kendo.template($("#RatingSettingsTemplate").html()),
        pageable: {
            refresh: true,
            pageSizes: [15, 30, 45, "all"],
            buttonCount: 5
        },
        columns: [
            {
                field:"departmentName",
                title: "部门",
                width:"15%",
                headerAttributes: alignCenterAttribute,
                attributes: alignCenterAttribute
            },
            {
                field:"departmentStatus",
                title: "状态",
                width:"15%",
                editor: departmentStatusSwitchEditor,
                template: function (e) {
                    if (e.departmentStatus)
                        return '<span style="color: #51ff1b">启用</span>';
                    return '<span style="color: red">停用</span>';
                },
                headerAttributes: alignCenterAttribute,
                attributes: alignCenterAttribute
            },
            {
                title: "操作",
                command: ["edit"]
            }
        ]
    });
    function departmentStatusSwitchEditor(container, options) {
        var checked = options.model.departmentStatus;
        $('<input type="checkbox" name="' + options.field + '" data-role="switch" class="km-widget"/>')
            .appendTo(container)
            .kendoMobileSwitch({
                checked: checked,
                onLabel: "启用",
                offLabel: "停用"
            });
    }
</script>